package cn.thoughtworks.school.programCenter.entities.dto;

import cn.thoughtworks.school.programCenter.entities.Assignment;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Setter
@Getter
@NoArgsConstructor
public class AssignmentQuizData {

  private Long assignmentId;
  private Long quizId;
  private String type;
  private Long newQuizId;
  private Long organizationId;
  private Long creatorId;

  public AssignmentQuizData(Long assignmentId, Long quizId, String type, Long organizationId, Long creatorId) {
    this.assignmentId = assignmentId;
    this.quizId = quizId;
    this.type = type;
    this.organizationId = organizationId;
    this.creatorId = creatorId;
  }

  public static List<AssignmentQuizData> build(List<Assignment> assignments,Long organizationId, Long creatorId) {
    List<AssignmentQuizData> assignmentQuizDatas = new ArrayList<>();
    assignments.forEach(assignment -> assignment.getSelectedQuizzes().forEach(assignmentQuiz ->
      {
        assignmentQuizDatas.add(new AssignmentQuizData(assignment.getId(), assignmentQuiz.getQuizId(), assignment.getType(), organizationId, creatorId));
      }
    ));
    return assignmentQuizDatas;
  }
}